package cn.com.gaobb.controller;

import cn.com.gaobb.annotation.CheckToken;
import cn.com.gaobb.dto.ResultDTO;
import cn.com.gaobb.service.OrderService;
import cn.com.gaobb.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author haopt
 * @version 1.0
 * @ClassName OrderController
 * @Description TODO
 * @date 2021/4/2 10:34
 */
@RestController
@RequestMapping("/api/order")
public class OrderController {
    @Autowired
    private OrderService OrderService;

    @CheckToken
    @PostMapping("/add")
    public ResultDTO<ResIdVO> add(@RequestBody ReqOrderAddVO reqVO,HttpServletRequest request) {
        return OrderService.add(reqVO,request);
    }

    @PostMapping("/update")
    public ResultDTO update(@RequestBody ReqOrderUpdateVO vo) {
        return OrderService.update(vo);
    }

    @PostMapping("/deleteList")
    public ResultDTO deleteList(@RequestBody ReqOrderDeleteListVO vo) {
        return OrderService.deleteList(vo);
    }

    @GetMapping("/detail")
    public ResultDTO<ResOrderDetailVO> detail(@RequestParam("id")String id) {
        return OrderService.detail(id);
    }

    @PostMapping("/listOfPage")
    public ResultDTO<ResPageVO<ResOrderDetailVO>> listOfPage(@RequestBody ReqPageVO vo) {
        return OrderService.listOfPage(vo);
    }

    @CheckToken
    @PostMapping("/listOfPageOfId")
    public ResultDTO<ResPageVO<ResOrderDetailVO>> listOfPageOfId(@RequestBody ReqPageVO vo, HttpServletRequest request) {
        return OrderService.listOfPageOfClientId(vo,request);
    }

    /**
     * 点击再次同意收货
     * @param vo
     * @return
     */
    @PostMapping("/receipt")
    public ResultDTO receipt(@RequestBody ReqReviewVO vo) {
        vo.setState(4);
        return OrderService.agreeOrDecline(vo);
    }

    /**
     * 点击获货物到达
     * @param vo
     * @return
     */
    @PostMapping("/arrivals")
    public ResultDTO arrivals(@RequestBody ReqReviewVO vo) {
        vo.setState(3);
        return OrderService.agreeOrDecline(vo);
    }

    /**
     * 点击发货
     * @param vo
     * @return
     */
    @PostMapping("/ship")
    public ResultDTO ship(@RequestBody ReqReviewVO vo) {
        vo.setState(2);
        return OrderService.agreeOrDecline(vo);
    }

    /**
     * 同意收货
     * @param vo
     * @return
     */
    @PostMapping("/agree")
    public ResultDTO agree(@RequestBody ReqReviewVO vo) {
        vo.setState(4);
        return OrderService.agreeOrDecline(vo);
    }

    /**
     * 拒绝收货
     * @param vo
     * @return
     */
    @PostMapping("/decline")
    public ResultDTO decline(@RequestBody ReqReviewVO vo) {
        vo.setState(5);
        return OrderService.agreeOrDecline(vo);
    }
}
